function HandlePageTransfer(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  
  this._nowstamp = (options && options.nowstamp) ? options.nowstamp : null;
 
  this._page = 1;
  this._order = 'd.id';
  this._queue = 'DESC';
  this._search = { keyword: '',
                   dateFrom: null,
                   dateTo: null
                 };
  this._lag = 0;
  if (this._nowstamp) {
    this._lag = SimpleDate.toStamp(SimpleDate.create(this._now.year, this._now.month, this._now.date)) - this._nowstamp;
  }

  this._createElements();
};

HandlePageTransfer.prototype._createElements = function() {
  var _self = this;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  this._transfer = pz_transfer.instance();
  this._transfer.transferDate = null;
  
  tr = this._gui.mains.insertRow(-1);
  td = tr.insertCell(-1);
  td.colSpan = 8;
  td.style.backgroundColor = '#fff';
  td.style.borderRight = 'solid 1px #694247';
  td.style.borderBottom = 'solid 1px #694247';
  td.style.borderLeft = 'solid 1px #694247';
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._loadData();
};

HandlePageTransfer.prototype._loadData = function() {
  this._results = null;
  this._users = null;
  this._transfers = null;
  this._parameters = null;
  this._retrieveTransfers();
  this._retrieveResults();
  this._retrieveUsers();
};

HandlePageTransfer.prototype._verifyData = function() {
  if (this._results && this._users && this._transfers) {
    this._updateElements();
  }
};

HandlePageTransfer.prototype._retrieveResults = function(pos) {
  var _self = this;
  var condition = HandleSearchTransfer.toSql(this._search, this._lag);
  var args = ((condition) ?  '&c=' + encodeURIComponent(condition) : '');
  new RequestUtils()._mysql('ietransfer', args, function(result, params) { _self._results = result;
                                                                           _self._verifyData.call(_self);
                                                                         }, { pos: ((pos) ? pos : null) });
};

HandlePageTransfer.prototype._retrieveTransfers = function(pos) {
  var _self = this;
  var condition = HandleSearchTransfer.toSql(this._search, this._lag);
  var args = ((condition) ?  '&c=' + encodeURIComponent(condition) : '') + '&p=' + this._page + '&s=20' + '&o=' + this._order + '&q=' + this._queue;
  new RequestUtils()._mysql('ietransfers', args, function(result, params) { _self._transfers = result.data;
                                                                           _self._parameters = result;
                                                                           _self._verifyData.call(_self);
                                                                         }, { pos: ((pos) ? pos : null) });
};

HandlePageTransfer.prototype._retrieveUsers = function() {
  var _self = this;
  new RequestUtils()._read('pz_user', null, null, null, null, 'd.account', null, function(result, params) { _self._users = result.data;
                                                                                                            _self._verifyData.call(_self);
                                                                                                          }, null);
};

HandlePageTransfer.prototype._updateElements = function() {
  var _self = this;
  DlmanageUtils.clear(this._gui.summarize);
  DlmanageUtils.clear(this._gui.add);
  DOMUtils.removeChildElements(this._gui.pagination);
  DOMUtils.removeTableRows(this._gui.mains, 2);

  this._gui.summarize.transfer.appendChild(document.createTextNode('$' + parseFloat(this._results.transfer).toFixed(2)));
  this._gui.summarize.cash.appendChild(document.createTextNode('$' + parseFloat(this._results.cash).toFixed(2)));
  this._gui.summarize.nonCash.appendChild(document.createTextNode('$' + parseFloat(this._results.noncash).toFixed(2)));
  
  //transfer排序
  this._gui.cdate.onclick = function() { _self._order = 'd.createdDate'; _self._queue = (_self._queue && _self._queue == 'ASC') ? 'DESC' : 'ASC'; _self._retrieveTransfers.call(_self); return false;
                                       };
  this._gui.tdate.onclick = function() { _self._order = 'd.transferDate'; _self._queue = (_self._queue && _self._queue == 'ASC') ? 'DESC' : 'ASC'; _self._retrieveTransfers.call(_self); return false;
                                       };
  this._gui.transferTo.onclick = function() { _self._order = 'd.transferTo'; _self._queue = (_self._queue && _self._queue == 'ASC') ? 'DESC' : 'ASC'; _self._retrieveTransfers.call(_self); return false;
                                       };
  this._gui.user.onclick = function() { _self._order = 'd.transferfrom'; _self._queue = (_self._queue && _self._queue == 'ASC') ? 'DESC' : 'ASC'; _self._retrieveTransfers.call(_self); return false;
                                      };
  //transfer添加
  this._transfer.transferfrom_trackId = this._operator.trackId;
  this._transfer.transferfrom = this._operator.account;
  this._transfer.createdDate = this._now;
  
  this._gui.add.createdDate.appendChild(document.createTextNode(SimpleDate.format(this._now)));
  this._gui.add.transferDate.value = (this._transfer.transferDate) ? SimpleDate.format(this._transfer.transferDate) : '';
  this._gui.add.transferDate.onclick = function() { var context = this;
                                                    _self._changeDate.call(_self, this, _self._transfer.transferDate, function(sd) { _self._transfer.transferDate = sd; context.focus(); }, false);
                                                    return false;
                                                  };
  this._gui.add.transferTo.who.options[this._gui.add.transferTo.who.options.length] = new Option('');
  for (var i = 0, il = this._users.length; i < il; i++) {
    var u = this._users[i];
    if (u.type == Constant.USER_TYPE_ADMINISTER) {
      continue;
    }
    var option = new Option(u.account);
    option._u = u;
    this._gui.add.transferTo.who.options[this._gui.add.transferTo.who.options.length] = option;
    if (option._u.trackId == this._transfer.transferto_trackId){
      this._gui.add.transferTo.who.selectedIndex = this._gui.add.transferTo.who.options.length - 1;
    }
  }
  if (this._users.length > 0) {
    this._gui.add.transferTo.who._index = this._gui.add.transferTo.who.selectedIndex;
    this._gui.add.transferTo.who.onchange = function() { _self._transfer.transferto = (this.options[this.selectedIndex]._u) ? this.options[this.selectedIndex]._u.account : ''; 
                                                         _self._transfer.transferto_trackId = (this.options[this.selectedIndex]._u) ? this.options[this.selectedIndex]._u.trackId : '';
                                                         _self._updateElements();
                                                       };
  }
  
  this._gui.add.c.checked = (this._transfer.method == 'C');
  this._gui.add.b.checked = (this._transfer.method == 'B');
  this._gui.add.q.checked = (this._transfer.method == 'Q');
  this._gui.add.c.onclick = function() { _self._transfer.method = 'C';};
  this._gui.add.b.onclick = function() { _self._transfer.method = 'B';};
  this._gui.add.q.onclick = function() { _self._transfer.method = 'Q';};
  
  this._gui.add.amount.onchange = function() { _self._transfer.amount = this.value; };
  this._gui.add.note.onchange = function() { _self._transfer.note = this.value; };
  
  this._gui.add.user.appendChild(document.createTextNode(this._transfer.transferfrom));
  
  this._gui.add.add.onclick = function() { if (!_self._transfer.transferDate) {
                                             window.alert('请填写转账时间');
                                             return;
                                           } else if(!_self._transfer.transferto) {
                                             window.alert('请选择转账给谁');
                                             return;
                                           } else if (_self._gui.add.amount.value == '' || _self._gui.add.amount.value == 0) {
                                             window.alert('数值不能为\'' + _self._gui.add.amount.value + '\'');
                                             return;
                                           } else if (!_self._transfer.method) {
                                             window.alert('请选择转账类型');
                                             return;
                                           } else {
                                             new RequestUtils()._write('pz_transfer', [_self._transfer], [], function() { location.reload(); }, { pos: DOMUtils.findPos(this) });
                                           }
                                         };
  //payments列表显示
  if (this._transfers.length == 0) {
    tr = this._gui.mains.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.backgroundColor = '#fff';
    td.colSpan = 8;
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.style.borderLeft = 'solid 1px #694247';
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('N/A'));
  }

  for (var i = 0, il = this._transfers.length; i < il; i++) {
    var transfer = this._transfers[i];
    tr = this._gui.mains.insertRow(-1);
    tr.className = (tr.rowIndex % 2 == 0) ? 'roweven' : 'rowodd';
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 10px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.style.borderLeft = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(SimpleDate.format(transfer.createdDate)));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 10px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(SimpleDate.format(transfer.transferDate)));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 10px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(transfer.transferto));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 10px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode('$' + transfer.amount));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 10px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(transfer.method));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 10px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.color = '#ff0000';
      if (transfer.cancelledMessage && transfer.cancelledMessage.length > 0) {
        td.appendChild(document.createTextNode('delete: ' + ((transfer.cancelledMessage.length > 27) ? transfer.cancelledMessage.substring(0, 27) + '...' : transfer.cancelledMessage)));
        var a = document.createElement('a');
        a.href = '#';
        a._transfer = transfer;
        a.appendChild(document.createTextNode('All'));
        a.onclick = function() { func1 = function() { _self._popupBox2._close(); };
                                 var pos = DOMUtils.findPos(this);
                                 var div = document.createElement('div');
                                 div.style.verticalAlign = 'top';
                                 div.style.width = '420px';
                                 div.style.color = '#ff0000';
                                 div.style.textAlign = 'left';
                                 div.style.padding = '4px 0 0 10px';
                                 div.style.wordWrap = 'break-word';
                                 div.appendChild(MiscUtils.span('\n' + this._transfer.cancelledMessage));
                                 MiscUtils.dialog(_self._popupBox2, pos, div, func1, null, {t: 'Cancel Reason (' + this._transfer.cancelledOperator + ', ' + SimpleDate.format(this._transfer.cancelledDate) + ')', width: 460, height: 100});
                                 return false;
                               };
        td.appendChild(a);
      } else {
        td.appendChild(document.createTextNode('(none)'));
      }
    } else {
      if (transfer.note && transfer.note.length > 0) {
        td.appendChild(document.createTextNode((transfer.note.length > 27) ? transfer.note.substring(0, 27) + '...' : transfer.note));
        var a = document.createElement('a');
        a.href = '#';
        a._transfer = transfer;
        a.appendChild(document.createTextNode('All'));
        a.onclick = function() { func1 = function() { _self._popupBox._close(); };
                                 var pos = DOMUtils.findPos(this);
                                 var div = document.createElement('div');
                                 div.appendChild(MiscUtils.span('\n' + this._transfer.note));
                                 MiscUtils.dialog(_self._popupBox, pos, div, func1, null);
                                 return false;
                               };
        td.appendChild(a);
      } else {
        td.appendChild(document.createTextNode('(none)'));
      }
      var a = document.createElement('a');
      a.href = '#';
      a.style.padding = '0 0 0 3px';
      a.appendChild(document.createTextNode('改'));
      a._transfer = transfer;
      a.onclick = function() { var pos = DOMUtils.findPos(this);
                                var div = document.createElement('div');
                                var transfer = this._transfer;
                                var func1 = function() { transfer.note = transfer._text;
                                                         new RequestUtils()._write('pz_transfer', [transfer], [], function() { _self._retrieveResults(); _self._retrieveTransfers(); }, { pos: pos });
                                                         _self._popupBox2._close();
                                                       };
                                var func2 = function() { _self._popupBox2._close(); };
                                MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Modify Note'});
                                new DialogInput(div, transfer, {default: transfer.note});
                                return false;
                              };
      td.appendChild(a);
    }
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 10px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(transfer.transferfrom));
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    var remove = document.createElement('img');
    remove.src = 'images/common/delete.png';
    remove.style.cursor = 'pointer';
    remove._transfer = transfer;
    remove.onclick = function() { var pos = DOMUtils.findPos(this);
                                  var div = document.createElement('div');
                                  var transfer = this._transfer;
                                  var func1 = function() { transfer.status = -1;
                                                           transfer.cancelledDate = _self._now;
                                                           transfer.cancelledOperator = _self._operator.account;
                                                           transfer.cancelledMessage = transfer._text;
                                                           new RequestUtils()._write('pz_transfer', [transfer], [], function() { _self._retrieveResults(); _self._retrieveTransfers(); }, { pos: pos });
                                                           _self._popupBox2._close();
                                                         };
                                  var func2 = function() { _self._popupBox2._close(); };
                                  MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Cancel Reason'});
                                  new DialogInput(div, transfer, { title: '' });
                                  return false;
                                };
    if (transfer.status != -1) {
      td.appendChild(remove);
    }
  }

  Pagination.makePagedResults(this._gui.pagination, this._parameters.page, this._parameters.total, this._parameters.size, function(page) { _self._page = page, _self._retrieveTransfers.call(_self); }, this, document);
  
  new HandleSearchTransfer(this._gui.search, this._operator, this._now, { search: this._search, callbackFunc: function(search) { _self._search = search; _self._page = 1; _self._retrieveResults.call(_self); _self._retrieveTransfers.call(_self); } });
};

HandlePageTransfer.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandlePageTransfer.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandlePageTransfer.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};